-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Split sync and async API #50
Conversation
I'll go ahead and merge this. |
let user_defaults: *mut NSObject = msg_send![class!(NSUserDefaults), standardUserDefaults]; | ||
let apple_domain = NSString::from_str("Apple Global Domain"); | ||
let dict: *mut NSObject = msg_send![user_defaults, persistentDomainForName:&*apple_domain]; | ||
|
||
if !dict.is_null() { | ||
let style_key = NSString::from_str("AppleInterfaceStyle"); | ||
let style: *mut NSObject = msg_send![dict, objectForKey:&*style_key]; | ||
|
||
if !style.is_null() { | ||
// Compare with "Dark" | ||
let dark_str = NSString::from_str("Dark"); | ||
let is_dark: bool = msg_send![style, isEqualToString:&*dark_str]; | ||
is_dark | ||
} else { | ||
false | ||
} | ||
} else { | ||
false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tip: You can avoid the brittle msg_send!
here by importing NSUserDefaults
from objc2-foundation
(might have to modify Cargo.toml
to include the "NSUserDefaults"
Cargo feature first).
The new synchronous |
We could instead provide only the sync version of |
I didn't consider that using |
This pull request introduces several changes to the codebase to add support for both synchronous and asynchronous detection and subscription to system theme changes.
The changes include modifications to dependencies, new feature flags, and refactoring of existing code to accommodate the new functionality.
Warning
These are breaking changes, we should consider shipping v2.0.0 after merging this.
Dependency and feature flag updates:
Cargo.toml
: Addedsync
feature flag and updatedpollster
to be optional. Introduced new example paths forsync
and added thecocoa
andobjc
dependencies for macOS support.Refactoring and new functionality:
src/lib.rs
: Moved theMode
enum to a newmode
module and updated thedetect
andsubscribe
functions to support both synchronous and asynchronous operations.src/mode.rs
: Created a new module for theMode
enum and its associated methods.src/platforms/*
: Refactored platform-specific detection and subscription functions to support both synchronous and asynchronous operations. This includes changes in macOS, freedesktop, websys, and windows modules.Example updates:
examples/async.rs
: Added a new asynchronous example demonstrating the use of thedetect
andsubscribe
functions.examples/sync.rs
: Added a new synchronous example demonstrating the use of thedetect
andsubscribe
functions.detect.rs
andnotify.rs
as they were replaced by the newasync.rs
andsync.rs
examples.Fixes: